<?php
/**
 * @title 5464. 换酒问题 - 迭代
 * @author start2004
 */

class Solution {

    /**
     * @param Integer $numBottles
     * @param Integer $numExchange
     * @return Integer
     */
    function numWaterBottles($numBottles, $numExchange) {
        /**
         * @since 2020-07-19 总酒瓶数量
         */
        $sum = $numBottles;

        /**
         * @since 2020-07-19 迭代
         */
        while($numBottles>=$numExchange){
            $add = intval($numBottles/$numExchange);
            $sum += $add;

            /**
             * @since 2020-07-19 空瓶总数
             */
            $numBottles = $add + $numBottles % $numExchange;
        }

        /**
         * @return
         */
        return $sum;
    }
}




/**
 * @url http://127.0.0.1/leetcode/202007/2020.07.19.php
 */
$datas = [
    [9,3],
    [5,3],
    [5,5],
    [2,3],
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    var_dump($data);

    $obj = new Solution();
    $result = $obj->numWaterBottles($data[0], $data[1]);
    var_dump($result);
    echo str_repeat("<br>", 3);
}
$xhprof->end();
